/*********************************************************************
 * PoolableObjectFactorySample.java created on Feb 2, 2010
 *
 * This file is part of Sure Tech Support Portal System. 
 * Copyright @ 2010 Sure Tech (HK) Limited. All rights reserved.
 * Sure Tech PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *********************************************************************/
package com.bizdigger.db;

import org.apache.commons.pool.PoolableObjectFactory;

/**
 * @Author: Mac Wang
 * @Date: Feb 2, 2010 1:55:30 PM 
 * @Email: mac@suretech.com.hk
 */

public class PoolableObjectFactorySample implements PoolableObjectFactory 
{
	private static int counter = 0;

	@Override
	public void activateObject(Object obj) throws Exception {
		System.out.println("activate object:" + obj);
	}

	@Override
	public void destroyObject(Object obj) throws Exception {
		System.out.println("destroy object:" + obj);
	}

	@Override
	public Object makeObject() throws Exception {
		Object obj = String.valueOf(counter++);
		System.out.println("make object: " + obj);
		return obj;
	}

	@Override
	public void passivateObject(Object obj) throws Exception {
		System.out.println("passivate object:" + obj);
	}

	@Override
	public boolean validateObject(Object obj) {
		boolean result = (Math.random() > 0.5);
		System.out.println("validate object: " + obj + " : " + result);
		return result;
	}

}
